package com.gxa.wmcrm.controller;

import com.alibaba.fastjson.JSON;
import com.gxa.wmcrm.service.EmployeeService;
import com.gxa.wmcrm.service.Impl.EmployeeServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "QueryEmployeeCountServlet", urlPatterns = "/QueryEmployeeCountServlet")
public class QueryEmployeeCountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json; charset=utf-8");
        //调用queryDepartmentCount()方法获取department表的记录条数
        EmployeeService employeeService = new EmployeeServiceImpl();
        int count = employeeService.queryEmployeeCount();
        //返回记录条数
        Map<String,Object> map = new HashMap<>();
        String message;
        PrintWriter out = response.getWriter();
        map.put("Count", count);
        map.put("Status","success");
        message = JSON.toJSONString(map);
        out.print(message);
    }
}

